var weekPieChart = echarts.init(document.querySelector(".week-graph"))
var weekBarChart = echarts.init(document.querySelector(".week-graph-2"))
var weekPieOption = {
	title: {
		text: "饼状图数据展示",
		left: "center",
    padding: [24, 0, 0, 0],
	},
	tooltip: {
		trigger: "item",
	},

	series: [
		{
			name: "Access From",
			type: "pie",
			radius: "50%",
			data: [],
			emphasis: {
				itemStyle: {
					shadowBlur: 10,
					shadowOffsetX: 0,
					shadowColor: "rgba(0, 0, 0, 0.5)",
				},
			},
		},
	],
}
var weekBarOption = {
  title: {
		text: "柱状图数据展示",
		left: "center",
    padding: [24, 0, 0, 0],
	},
  xAxis: {
    type: 'category',
    data: []
  },
  yAxis: {
    type: 'value',
    name:'商品数'
  },
  series: [
    {
      data: [],
      type: 'bar'
    }
  ]
}
getData({ type: "week" }).then((res) => {
	let sales = res.data.data.series
	let week = res.data.data.xAxis
	/**
	 *  两个数组合并成一个对象数组
	 *  {week,sales:sales[index]}是一个对象
	 *  所以箭头函数返回时要加个括号
	 */
	this.weekPieOption.series[0].data = week.map((week, index) => ({
		name: week,
		value: sales[index],
	}))
  this.weekBarOption.xAxis.data = week
  this.weekBarOption.series[0].data = sales
  // 避免渲染在加载完成前
	weekPieChart.setOption(weekPieOption)
	weekBarChart.setOption(weekBarOption)
})
